import type { MutationTree, ActionTree, GetterTree } from 'vuex'
import type { IRootState } from './index'
import { Actions, Mutations } from '@/enum/industryMap'

export interface ICityState {
  areaName: string | undefined
  areaCode: string | undefined
  parkName: string | undefined
}

export const state: () => ICityState = () => ({
  areaName: '重庆市',
  areaCode: '500000',
  parkName: '',
})

export const mutations: MutationTree<ICityState> = {
  [Mutations.SET_AREA](state, { name, code }) {
    state.areaName = name
    state.areaCode = code
  },
  [Mutations.SET_PARK_NAME](state, name) {
    state.parkName = name
  },
}

export const actions: ActionTree<ICityState, IRootState> = {
  // [Actions.getCity]({ commit }) {
  //   // 接口获取当前定位城市
  //   // 获取不到默认为重庆
  //   commit(Mutations.SET_AREA, {
  //     name: '渝北区',
  //     code: '500000',
  //   })
  // },
}

export const getters: GetterTree<ICityState, IRootState> = {
  areaName: (state) => state.areaName,
  areaCode: (state) => state.areaCode,
  parkName: (state) => state.parkName,
}
